
import { BaseModel, sequelize, Sequelize } from "./basemodel.js";

class Grades extends BaseModel {
	static init() {
		return super.init(
			{
				
				grade_id: { type: Sequelize.INTEGER, primaryKey: true, defaultValue: Sequelize.literal('DEFAULT') ,autoIncrement: true},
				enrollment_id: { type:Sequelize.INTEGER  ,defaultValue: Sequelize.literal('DEFAULT') },
				daily_grade: { type:Sequelize.NUMBER  ,defaultValue: Sequelize.literal('DEFAULT') },
				exam_grade: { type:Sequelize.NUMBER  ,defaultValue: Sequelize.literal('DEFAULT') },
				homework_grade: { type:Sequelize.NUMBER  ,defaultValue: Sequelize.literal('DEFAULT') },
				final_grade: { type:Sequelize.NUMBER  ,defaultValue: Sequelize.literal('DEFAULT') },
				teacher_feedback: { type:Sequelize.STRING  ,defaultValue: Sequelize.literal('DEFAULT') },
				last_updated: { type:Sequelize.DATE , allowNull: false  },
				updated_by: { type:Sequelize.INTEGER  ,defaultValue: Sequelize.literal('DEFAULT') },
				teacher_signature: { type:Sequelize.STRING  ,defaultValue: Sequelize.literal('DEFAULT') },
				semester_name: { type:Sequelize.STRING  ,defaultValue: Sequelize.literal('DEFAULT') }
			}, 
			{ 
				sequelize,
				
				tableName: "grades",
				modelName: "grades",
			}
		);
	}
	
	static listFields() {
		return [
			// grades 表字段
			Sequelize.literal('grades.grade_id AS grade_id'),
			Sequelize.literal('grades.enrollment_id AS enrollment_id'),
			Sequelize.literal('grades.daily_grade AS daily_grade'),
			Sequelize.literal('grades.exam_grade AS exam_grade'),
			Sequelize.literal('grades.homework_grade AS homework_grade'),
			Sequelize.literal('grades.final_grade AS final_grade'),
			Sequelize.literal('grades.teacher_feedback AS teacher_feedback'),
			Sequelize.literal('grades.last_updated AS last_updated'),
			Sequelize.literal('grades.updated_by AS updated_by'),
			Sequelize.literal('grades.semester_name AS semester_name'),
			Sequelize.literal('grades.teacher_signature AS teacher_signature'),
			// 修改关联表字段引用方式
			Sequelize.literal('enrollment.course_name AS course_name'),
			Sequelize.literal('enrollment.enrollment_date AS enrollment_date'),
			// 修改学生信息字段引用方式
			Sequelize.literal('`enrollment->student`.name AS student_name'),
			Sequelize.literal('`enrollment->student`.personnel_id AS student_id'),
			Sequelize.literal('`enrollment->student`.avatar_url AS student_avatar')
		];
	}

	static viewFields() {
		return [
			'grade_id', 
			'enrollment_id', 
			'daily_grade', 
			'exam_grade', 
			'homework_grade', 
			'final_grade', 
			'teacher_feedback', 
			'last_updated', 
			'updated_by', 
			'teacher_signature'
		];
	}

	static editFields() {
		return [
			'grade_id', 
			'enrollment_id', 
			'daily_grade', 
			'exam_grade', 
			'homework_grade', 
			'final_grade', 
			'teacher_feedback', 
			'updated_by', 
			'teacher_signature'
		];
	}

	
	static searchFields(){
		return [
			Sequelize.literal("grade_id LIKE :search"), 
			Sequelize.literal("teacher_feedback LIKE :search"), 
			Sequelize.literal("teacher_signature LIKE :search"),
		];
	}

	
	
}
Grades.init();
export default Grades;
